package com.hc.weatherhc.job;

import com.hc.weatherhc.domain.City;

import com.hc.weatherhc.domain.WeatherResponse;
import com.hc.weatherhc.service.CityService;
import com.hc.weatherhc.service.WeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TimerTaskJob {

    @Autowired
    CityService cityService;  //获取城市列表数据
    @Autowired
    WeatherService weatherService;

    @Scheduled(cron="0,30 * * * * *")  //每隔30分钟触发一次
    public void cacheWeatherDataJob(){
        System.out.println("我在缓存天气数据。。。。。。。。。。。。"+new Date());

        //抓取最新的天气数据
        List<City> cityList=cityService.cityList();

        for(City c:cityList){
            WeatherResponse weatherResponse=weatherService.fetchWeatherData(c.getCityId());
            System.out.println("weatherResponse:"+weatherResponse);
        }

    }
}
